<?php
/**
 * Created by PhpStorm.
 * User: xaq
 * Date: 2017/5/31
 * Time: 13:57
 */

namespace app\api\controller\v1;


use app\api\controller\BaseController;
use app\api\service\Token as TokenService;
use app\api\model\User as UserModel;
use app\lib\exception\SuccessMessage;
use app\lib\exception\UserException;

class User extends BaseController
{
    public function setScore() {
        $uid = TokenService::getCurrentUid();
        $score = input('post.score');
        $subject = input('post.subject');
        $result = new UserModel;
        $result->where('id', '=',$uid)
            ->update(['score' =>$score,'subject'=>$subject]);
        //return int
//        $result = UserModel::where('id','=',$uid)
//            ->update(['score' =>$score,'subject'=>$subject]);
        var_dump($result);
        if(!$result) {
            throw new UserException();
        }
        return  json((new SuccessMessage(['msg' => '更新成功'])),201);
    }
}